package com.chebaohui.iqs.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.chebaohui.iqs.entity.db.DbParam;
import com.chebaohui.iqs.mapper.DbParamMapper;
import com.chebaohui.iqs.sdk.IdWorker;
import com.chebaohui.iqs.service.DBService;
import com.chebaohui.iqs.service.impl.deal.util.StringUtil;

@Service
public class DBServiceImpl implements DBService {

	@Autowired
	private DbParamMapper mapper;

	@Override
	public List<DbParam> query(DbParam param) throws Exception {
		try {
			return mapper.queryAll(param);
		} catch (Exception e) {
			throw new Exception("数据库查询异常:" + e.getMessage());
		}
	}

	@Override
	public void add(DbParam param) throws Exception {
		try {
			if (StringUtil.isNulls(param.getId()))
				param.setId(IdWorker.getId().toString());
			mapper.insert(param);
		} catch (Exception e) {
			throw new Exception("数据库数据插入异常:" + e.getMessage());
		}
	}

	@Override
	public void undate(DbParam param) throws Exception {
		try {
			mapper.update(param);
		} catch (Exception e) {
			throw new Exception("数据库数据更新异常:" + e.getMessage());
		}
	}

	@Override
	public void delete(DbParam param) throws Exception {
		try {
			mapper.delect(param);
		} catch (Exception e) {
			throw new Exception("数据库数据删除异常:" + e.getMessage());
		}
	}

}
